package com.example.win.android_banduyujia.peopleactivity.activity.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.lib.util.StrUtils;
import com.example.win.android_banduyujia.peopleactivity.ui.model.PhotoModel;
import com.example.win.android_banduyujia.peopleactivity.ui.activity.BaseTitleBarActivity;
import com.example.win.android_banduyujia.peopleactivity.ui.image.PhotoSelectorActivity;
import com.example.win.android_banduyujia.ui.popupWindow.Popupwindows;
import com.example.win.android_banduyujia.peopleactivity.ui.util.CommonUtils;
import com.example.win.android_banduyujia.venuesactivity.activity.houractivtiy.CernameActivity;
import com.example.win.android_banduyujia.venuesactivity.activity.houractivtiy.HourActivity;
import com.example.win.android_banduyujia.venuesactivity.activity.houractivtiy.HournameActivity;
import com.example.win.android_banduyujia.venuesactivity.activity.houractivtiy.OriganActivity;
import com.example.win.android_banduyujia.venuesactivity.activity.houractivtiy.TeachingActivity;

import java.util.List;

/**
 * Created by huchun on 2015/8/20.
 */
public class HonorActivity extends BaseTitleBarActivity implements View.OnClickListener {
    public static final String  TAG = HonorActivity.class.getSimpleName();

    public RelativeLayout  LayoutPicture;
    public ImageView  mImageHonor;
    public TextView   mTxtPicture;

    public LinearLayout LayoutName;
    public TextView   mTxthonor;

    public Button     mBtnAdd;

    private Popupwindows mPopupwindows;
    private View    view;
    private String  mFinish = " ";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_honor_book);

        InitTitles();
        InitViews();
    }

    private void InitTitles() {
        setTitle(R.string.text_view_letter_credit);
        showLeftBackButton();
        setRightTextViewListener(R.string.text_view_submit_audit_finish, onRightListener);
    }

    private View.OnClickListener onRightListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(StrUtils.isEmpty(mFinish)){
                showToast("完成");
            }
            Finish();
        }
    };

    private void Finish() {

    }

    private void InitViews() {
        LayoutPicture = (RelativeLayout)findViewById(R.id.layout_relative_picture);
        mImageHonor = (ImageView) findViewById(R.id.layout_name_book_image_view);
        mTxtPicture = (TextView) findViewById(R.id.title_list_item_phone);

        LayoutName = (LinearLayout) findViewById(R.id.layout_view_honor_cer_name);
        mBtnAdd = (Button) findViewById(R.id.layout_button_data_add);

        LayoutPicture.setOnClickListener(this);
        mImageHonor.setOnClickListener(this);
        mTxtPicture.setOnClickListener(this);

        LayoutName.setOnClickListener(this);
        mBtnAdd.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.layout_relative_picture:
                gotoUploadActivity();
                break;
            case R.id.layout_name_book_image_view: // 上传证书照片
                gotoUploadActivity();
                break;
            case R.id.title_list_item_phone:// 文本
                gotoUploadActivity();
                break;
            case R.id.layout_view_honor_cer_name: // 证书名称
                gotoCernameActivity();
                break;
            /*case R.id.layout_view_honor_teaching: // 培训名师
                gotoTeachingActivity();
                break;
            case R.id.layout_view_honor_organization: // 机构
                 gotoOriganActivity();
                break;
            case R.id.layout_view_honor_name:  // 课程名称
                gotoHonornameActivity();
                break;
            case R.id.layout_view_honor_hour: // 瑜伽教培小时
                 gotoHourActivity();
                break;*/
            case R.id.layout_button_data_add:
                 gotoDataActivity();
                break;
        }
    }

    private void gotoUploadActivity() {
        /*Popupwindows popupwindows = new Popupwindows(HonorActivity.this);
        popupwindows.showAtLocation(mImageHonor);*/
        CommonUtils.launchActivityForResult(this, PhotoSelectorActivity.class, 0);

    }

    private void gotoCernameActivity() {
        startActivity(new Intent(this, CernameActivity.class));
    }

    private void gotoTeachingActivity() {
        startActivity(new Intent(this, TeachingActivity.class));
    }

    private void gotoOriganActivity() {
        startActivity(new Intent(this, OriganActivity.class));
    }

    private void gotoHonornameActivity() {
        startActivity(new Intent(this, HournameActivity.class));
    }

    private void gotoHourActivity() {
        startActivity(new Intent(this, HourActivity.class));
    }

    private void gotoDataActivity() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 0 && resultCode == RESULT_OK){
            if(data != null && data.getExtras() !=null){
                List<PhotoModel> photos = (List<PhotoModel>) data.getExtras().getSerializable("photos");
                if(photos == null || photos.isEmpty())
                    return;
                StringBuffer  sb = new StringBuffer();
                for(PhotoModel photo : photos){
                    sb.append(photo.getOriginalPath() +"\r\n");
                }
            }
        }
    }
}
